<template>
  <views class="depart_manager_detail">
    <div>
      <viewTitle :title="'添加组织'" border></viewTitle>
      <div class="depart_manager_detail_input">
        <el-form ref="form" label-width="auto" :inline="true">
          <el-form-item label="部门名称:">
            <el-input type="text" clearable placeholder="请输入部门名称" v-model="department_name"></el-input>
          </el-form-item>
          <el-form-item label="上级部门:">
            <el-cascader
                    v-model="parent_id"
                    :options="department_list"
                    :props="{ checkStrictly: true }"
                    clearable></el-cascader>
          </el-form-item>
        </el-form>
        <div>
              <el-row>
                <el-button type="primary" @click="submit">提交</el-button>
                <el-button @click="reset">重置</el-button>
                <el-button @click="goBlack" type="danger">返回</el-button>
              </el-row>
        </div>
      </div>
    </div>
  </views>
</template>


<script>
export default {
  data() {
    return {
      department_id: 0, //  部门ID
      department_name: "", //  部门名称
      parent_id: "", //  上级部门
      department_list: [],
    };
  },
  methods: {
           // 提交
           submit(){
               //console.log('parent_id',this.parent_id);
               console.log('post_data',this.post_data);
               // return
               this.$raxios.post(
                   this.$mapapi.admin_entryDepartment,
                   {data:this.post_data}
               ).then(res=>{
                 if(res.code==200){
                   this.$message.success('添加成功');
                   this.$router.go(-1);
                 }else{
                    this.$message.error(res.msg);
                   return;
                 }
               })            
           },
           // 重置
           reset(){
                this.parent_id = [];
                this.department_name = "";
           },
           goBlack(){
               this.$router.go(-1)
           }

  },
  computed:{
      post_data(){
          let data = {};
          if(this.department_id > 0){
              data.department_id = this.department_id;
          }
          data.department_name = this.department_name;
          data.parent_id = this.parent_id.slice(-1)[0] || 0;
          return data;
      }
  },
  created() {
      this.$raxios.post(
          this.$mapapi.admin_departmentTree,{}
      ).then(res=>{
          if (res.code == 200) {
           this.department_list = res.data;
          }else{
          this.$message.error(res.msg);
          this.department_list = [];
	          this.$message.error(res.msg)
          return;
          }
      })
     // console.log('data',data);
  },
  mounted() {}
};
</script>

<style lang="less" scope="true"  src='@/style/system_manager/depart_manager_detail.less'>
</style>
